package com.hhkj.study.admin.config.service.biz.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hhkj.study.admin.config.entity.ConfigCompany;
import com.hhkj.study.admin.config.model.podo.ConfigCompanyDo;
import com.hhkj.study.admin.config.model.podo.ConfigCompanyPo;
import com.hhkj.study.admin.config.model.req.ConfigCompanyReq;
import com.hhkj.study.admin.config.model.req.ConfigWelcomeReq;
import com.hhkj.study.admin.config.model.res.ConfigCompanyRes;
import com.hhkj.study.admin.config.service.base.ConfigCompanyService;
import com.hhkj.study.admin.config.service.biz.ConfigCompanyBizService;
import com.hhkj.study.admin.config.service.extend.ConfigCompanyExtendService;
import com.ruoyi.common.base.biz.service.biz.BaseBizServiceImpl;
import com.ruoyi.common.cont.SysConst;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.stereotype.Service;

/**
* ConfigCompanyBizServiceImpl
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ConfigCompanyBizServiceImpl extends BaseBizServiceImpl<ConfigCompany, ConfigCompanyReq, ConfigCompanyRes, ConfigCompanyDo, ConfigCompanyPo, ConfigCompanyService, ConfigCompanyExtendService> implements ConfigCompanyBizService {
    @Override
    public boolean updatePublishFlag(ConfigWelcomeReq req) {
        ConfigCompany configCompany = this.getExtendService().getByIdNotNull(req.getId());
        if (configCompany.getPublishedFlag().equals(req.getPublishedFlag())) {
            throw new GlobalException(SysConst.Flag.IS.getFlag().equals(req.getPublishedFlag()) ?
                    "已上架" : "已下架");
        }
        LambdaUpdateWrapper<ConfigCompany> configCompanyUpdate = new LambdaUpdateWrapper<>();
        configCompanyUpdate.eq(ConfigCompany::getId, req.getId())
                .set(ConfigCompany::getPublishedFlag, req.getPublishedFlag());
        return this.getService().update(configCompanyUpdate);
    }
}